<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('article_tags', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique(); // 标签名称
            $table->string('slug')->unique(); // URL友好标识
            // 颜色
            $table->string('color')->nullable()->comment('标签颜色');
            $table->timestamps();
            $table->comment('文章标签表');
        });

        Schema::create('article_has_tags', function (Blueprint $table) {
            $table->foreignId('article_id')->constrained()->onDelete('cascade');
            $table->foreignId('article_tag_id')->constrained()->onDelete('cascade');
            $table->primary(['article_id', 'article_tag_id']); // 联合主键
            $table->comment('文章标签关联表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('article_tags');
        Schema::dropIfExists('article_has_tags');
    }
};
